import vue from '@vitejs/plugin-vue';
import {ConfigEnv, defineConfig, loadEnv} from 'vite'
import path from 'path'
import VueSetupExtend from 'vite-plugin-vue-setup-extend';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
export default defineConfig(({ mode }: ConfigEnv) => {
	return {
		base: './',
		plugins: [
			vue(),
			VueSetupExtend(),
			AutoImport({
				resolvers: [ElementPlusResolver()]
			}),
			Components({
				resolvers: [ElementPlusResolver()]
			})
		],
		optimizeDeps: {
			include: ['schart.js']
		},
		resolve: {
			alias: {
				"@": path.resolve("./src") // 相对路径别名配置，使用 @ 代替 src
			}
		},
		server: {
			port: 99,
			host: '0.0.0.0',
			proxy: {
				'/api': {
					target: `${loadEnv(mode, process.cwd()).VITE_SERVE}`,
					changeOrigin: true,
					rewrite: (path) => path.replace(/^\/api/, '')
				},
			}
		}
	}
})
